﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace org.psantos.ff.ui
{
    public partial class Form1 : Form
    {
        private Dictionary<string, string> foldersToSync;

        public Form1()
        {
            InitializeComponent();
            this.foldersToSync = new Dictionary<string, string>();

        }

        private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
        {
            MessageBox.Show("Files changed");
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listView1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
        }

        private void listView1_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (string file in files)
            {
                Console.WriteLine(file);
                if (Directory.Exists(file))
                {
                    DirectoryInfo di = new DirectoryInfo(file);
                    string key = di.Parent.Name + " - "+ di.Name;
                    long dirSize=0;
                    foreach (FileInfo fsi in di.EnumerateFiles())
                    {
                        dirSize += fsi.Length;
                    }

                    listView1.Items.Add(new ListViewItem(new [] {di.Parent.Name, di.Name, ""+dirSize/(1024*1024)}));
                    this.foldersToSync.Add(key, file);
                }
            }
            MessageBox.Show("Files dropped");
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
